from clf_model import *
from require_classifier import *
import random

class ChatBotGraph:
    def __init__(self):
        self.classifier = RequireClassifier()
        original_dir = os.getcwd()
        current_dir = os.path.dirname(os.path.abspath(__file__))
        y_own_dir = os.path.join(current_dir, 'model_file')

        self.predictor = CLFModel(y_own_dir)

    def chat_main(self, sent):
        result = self.classifier.run_result(sent)
        # print("result:",result)
        if self.classifier.result_flag == True:
            return result
        else:
            label = self.predictor.predict(result)
            chitchat_corpus = {
                "greet": [
                    "hi",
                    "hello",
                    "你好呀",
                    "我是智能编程助手，有什么可以帮助你吗",
                    "hi，你好，你可以叫我智能编程助手",
                    "你好哦，请问有什么需要吗"
                ],
                "goodbye": [
                    "再见，很高兴为您服务",
                    "bye",
                    "再见，感谢使用我的服务",
                    "再见啦，欢迎再次使用"
                ],
                "deny": [
                    "对不起"
                    "很抱歉没帮到您",
                    "I am sorry",
                    "那您可以试着问我其他问题哟"
                ],
                "isbot": [
                    "我是你的智能编程助手",
                    "你可以叫我智能编程助手",
                    "我是智能编程助手"
                ],
                "accept": [
                    "好的",
                    "嗯嗯",
                    "谢谢"
                ],
                "ask": [
                    "我可以帮你进行代码质量的检测",
                    "我可以帮你检查代码风格",
                    "我可以指出你代码中存在的错误",
                    "我可以指出你代码中需要改进的地方"
                ]
            }
            # print(label)
            answer = random.choice(chitchat_corpus[label])
            return answer


if __name__ == '__main__':
    handler = ChatBotGraph()
    while 1:
        question = input('用户:')
        answer = handler.chat_main(question)
        # if isinstance(answer, list):
        #     print('Tom:')
        #     for item in answer:
        #         print(item)
        # else:
        print('Tom:', answer)